<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Common_login_manage extends CI_Controller {


	public function __construct() {
		session_start();
		parent::__construct();
		$this->load->library("common/login_manage");
	}

	public function index()
	{
		$this->login();

	}
	/**
	 *
	 *
		* @name login
		* @date 2013-1-9
		* @author eifel
		* @param
		* @return
		* @version 1.0
		* @description 根据用户名和密码返回登录的结果
	 */
	public function login() {
		$user_name	=trim($this->input->get_post("user_name"));
		$password	=trim($this->input->get_post("password"));
		$captcha	=trim($this->input->get_post("captcha"));
		$remember	=trim($this->input->get_post("remember"));
		if ($user_name==""||$password=="") {
			$data['result']		=false;
			$data['message']	="请输入您的用户名和密码";
		}else{
			$this->load->library("common/login_manage");
			$data=$this->login_manage->login($user_name,$password,$captcha,$remember);
		}
		if ($data['result']==true) {
			setcookie("user_name",$user_name, time()+3600*24*30);
		}
		echo  json_encode($data);
	}

	
	
	public function logout() {
		$this->login_manage->logout();
		redirect(base_url());
	}

	/**
	 *
	 *
		* @name need_captcha
		* @date 2013-1-9
		* @author eifel
		* @param
		* @return
		* @version 1.0
		* @description 判断是否需要登录验证码
	 */
	public function need_captcha() {
		$user_name		=	trim($this->input->get_post("user_name"));
		$this->load->library("common/login_manage");
		$data['result']	= 	$this->login_manage->need_captcha($user_name);
		echo json_encode($data);
	}

	/**
	 *
	 *
		* @name check_login
		* @date 2013-1-15
		* @author eifel
		* @param
		* @return
		* @version 1.0
		* @description
	 */
	public function check_login() {
		$this->load->library("common/login_manage");
		$data['result']	=$this->login_manage->check_login();
		echo json_encode($data);
	}

	/**
	 *
	 *
		* @name login_form
		* @date 2013-1-15
		* @author eifel
		* @param
		* @return
		* @version 1.0
		* @description 加载一个在用户提交表单时的登录框
	 */
	public function login_form() {
		$this->load->library("session");

		if (isset($_COOKIE['user_name'])) {
			$data['user_name']=$_COOKIE['user_name'];
		}else {
			$data['user_name']="";
		}
		$this->load->view('common/form_login',$data);
	}

	public function form_sign(){
		if (!isset($_COOKIE['user_name'])) {
			$data['result']=true;
			$data['message']="距离您上次登录已经太久,请返回主页重新登录";
			echo json_encode($data);
		}else{
			$password	=trim($this->input->get_post("password"));
			$captcha	="";
			$remember	="";
			$this->load->library("common/login_manage");
			$data=$this->login_manage->login($_COOKIE['user_name'],$password,$captcha,$remember);
			echo json_encode($data);
		}

	}
}

/* End of file common_login_manage.php */
/* Location: ./application/controllers/common_login_manage.php */